﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using f1;

namespace f1messsagebox
{

    public partial class Form1 : Form
    {
        Order order=new Order();
        int orderID, num;
        string name;
        BindingList<OrderDetail> list=new BindingList<OrderDetail>();
        
        public event ClickHandler CreateOrderhandler;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            { 
                order.Customer = textBox1.Text;
                order.Amount = Int32.Parse(textBox2.Text);
                order.Items = list.ToList();
            }
            catch (Exception ex)
            {
                MessageBox.Show("输入错误");
                return;
            }
           
            CreateOrderhandler(this, new CreateEventArgs(order));
            
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            orderID = Convert.ToInt32(textBox4.Text);
            num=Convert.ToInt32(textBox6.Text);
            name=textBox5.Text;
            OrderDetail orderDetail = new OrderDetail(orderID,name,num );
            list.Add(orderDetail);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = list;
        }
    }
    public delegate void ClickHandler(object sender, CreateEventArgs e);
    public class CreateEventArgs
    {
        public Order Order { get; set; }
        public CreateEventArgs(Order order)
        {
            Order = order;
        }
    }
}
